﻿using System;

namespace Program14
{
    //定义枚举
    public enum Gender
    {
        男,
        女,
        其它
    }

    public enum QQState
    {
        //枚举的成员可以定义它们的整型值
        online = 1,
        offline = 0,
        leave = 2,
        busy = 3,
        Qme = 4
    }

    class Program
    {
        static void Main(string[] args)
        {
            #region 将枚举类型转换成Int
            //QQState state = QQState.online;
            //int n = (int)state;
            //Console.WriteLine("QQ在线枚举成员的值:"+n);
            //Console.WriteLine("QQ离线枚举成员的值:" + (int)QQState.offline);
            //Console.WriteLine("QQ离开枚举成员的值:" + (int)QQState.leave);
            //Console.WriteLine("QQ忙碌枚举成员的值:" + (int)QQState.busy);
            //Console.WriteLine("QQ无聊枚举成员的值:" + (int)QQState.Qme);

            #endregion

            #region 将Int转换成枚举类型
            int n1 = 6;
            int n2 = 4;
            var state1 = (QQState)n1;
            var state2 = (QQState)n2;
            Console.WriteLine("QQ状态:" + state1);
            Console.WriteLine("QQ状态:" + state2);
            #endregion

            //#region 将字符串类型转换为枚举类型
            //string s = "男";
            //将“其它”转换成 Gender.其它
            //字符串类型转换为枚举类型语法，
            //Gender g = (Gender)Enum.Parse(typeof(Gender), s);
            //Console.WriteLine(g);
            //Console.WriteLine((int)g);
            //#endregion
        }
    }
}
